package ua.org.enginer.collections {

import mx.collections.ArrayCollection;

/**
 * Perfom filtering by all seted filterFunctions
 */ 
public class MultiFiltersArrayCollection extends ArrayCollection {
	
	[ArrayElementType(name="Function")]
	public var filterFunctions:Array = []
	
	public function MultiFiltersArrayCollection(source:Array=null) {
		super(source);
	}
	
	override public function set filterFunction(f:Function):void {
		filterFunctions.push(f)
	}
	
	override public function get filterFunction():Function {
		//return filterFunctions.length ? filterFunctions[0] : null
		if (!filterFunctions.length) return super.filterFunction
		if (filterFunctions.length == 1) return filterFunctions[0]
		return multipleFilterFunction
	}
	
	protected function multipleFilterFunction(item:Object):Boolean {
		for each(var filter:Function in filterFunctions) {
			if (!filter(item)) return false
		}
		return true
	}
}
}

